from base.views import TemplateView, ActionView

from flask import Blueprint, redirect, url_for, request
from flask_login import login_required, logout_user, login_user

from models import User, Tab, Tag
from utils import get_param


front = Blueprint('front', __name__)



class IndexView(TemplateView):
    template_name = 'index.html'

    def get_context_data(self):
        context = super().get_context_data()
        
        tag_id = get_param('tag', 'string', required=False,
            default=None, max_length=48, min_length=1)
        context['current_tag'] = Tag.get(tag_id=tag_id)
        context['tabs'] = Tab.all()

        return context


def register():
    front.add_url_rule('/', view_func=IndexView.as_view('index'))